/**********************************************
 * 
 * File Name				:	cookies.js
 * 
 * Last Changed Date		: 	$Date: 2009-08-01 11:12:53 +0800 (星期六, 01 八月 2009) $
 * 
 * Last Changed Revision	:	$Revision: 86 $
 * 
 * Last Changed Author		:	$Author: cfanboy $
 * 
 * File Header URL			:	$HeadURL: svn://www.svnhost.cn/Busi-Building/code/branch/WebContent/js/cookies.js $
 * 
 * ********************************************
 */
 
// Cookies method, used for store some information into Cookies.
var Cookies = {}; // Define the namespace

Cookies.setCookie = function(name, value) {
	var expdate = new Date();
	var argv = arguments;
	var argc = arguments.length;
	// if not set the expires, default is 30 days.
	var expires = (argc > 2) ? argv[2] : 30 * 24 * 60 * 60;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	if (expires != null)
		expdate.setTime(expdate.getTime() + (expires * 1000));

	document.cookie = name
			+ "="
			+ escape(value)
			+ ((expires == null) ? "" : (";  expires=" + expdate.toGMTString()))
			+ ((path == null) ? baseContext : (";  path=" + path))
			+ ((domain == null) ? "" : (";  domain=" + domain))
			+ ((secure == true) ? ";  secure" : "");
};

Cookies.getCookie = function(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
};

Cookies.clearCookie = function(name) {
	if (Cookies.getCookie(name)) {
		var exp = new Date();
		exp.setTime(exp.getTime() - 1);
		var cval = Cookies.getCookie(name);
		document.cookie = name + "=" + cval + ";  expires=" + exp.toGMTString();
	}
};

Cookies.getOriginalCookie = function(name) {
	var search = name + "=";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1)
				end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		} else
			return "";
	}
};